package model

import (
	"gorm.io/gorm"
	"time"
	"user_srv/basic/config"
)

type User struct {
	Id        uint           `gorm:"column:id;type:bigint(20) UNSIGNED;primaryKey;not null;" json:"id"`
	Nickname  string         `gorm:"column:nickname;type:varchar(20);comment:昵称;not null;" json:"nickname"`                                      // 昵称
	Age       uint           `gorm:"column:age;type:int(10);comment:年龄;not null;" json:"age"`                                                    // 年龄
	Sex       string         `gorm:"column:sex;type:varchar(10);comment:性别;not null;" json:"sex"`                                                // 性别
	Member    uint           `gorm:"column:member;type:tinyint(1) UNSIGNED;comment:会员等级:1:普通会员，2:中级会员，3:高级会员;not null;default:1;" json:"member"` // 会员等级:1:普通会员，2:中级会员，3:高级会员
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (u *User) TableName() string {
	return "user"
}
func (u *User) UpdateUser() error { //成为会员
	return config.DB.Model(&User{}).Where("id = ?", u.Id).Update("member", u.Member).Error
}
